package org.xxpay.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xxpay.core.entity.PayOrderLog;
import org.xxpay.core.entity.PayOrderLogExample;
import org.xxpay.core.service.IPayOrderLogService;
import org.xxpay.service.dao.mapper.PayOrderLogMapper;

import java.util.List;

/**
 * @author: pangxiaoyu
 * @date: 2020/02/24
 * @description: 订单日志
 */
@Service
public class PayOrderLogServiceImpl implements IPayOrderLogService {

    @Autowired
    private PayOrderLogMapper payOrderLogMapper;

    @Override
    public int add(PayOrderLog payOrderLog) {
        return payOrderLogMapper.insertSelective(payOrderLog);
    }

    @Override
    public int update(PayOrderLog payOrderLog) {
        return payOrderLogMapper.updateByPrimaryKeySelective(payOrderLog);
    }

    @Override
    public List<PayOrderLog> select(PayOrderLog payOrderLog) {
        PayOrderLogExample example = new PayOrderLogExample();
        PayOrderLogExample.Criteria criteria = example.createCriteria();
        if (payOrderLog != null) {
            if (StringUtils.isNotEmpty(payOrderLog.getPayOrderId())) criteria.andPayOrderIdEqualTo(payOrderLog.getPayOrderId());
            if (StringUtils.isNotEmpty(payOrderLog.getMchOrderNo())) criteria.andMchOrderNoEqualTo(payOrderLog.getMchOrderNo());
            if (payOrderLog.getType() != null) criteria.andTypeEqualTo(payOrderLog.getType());
            if (payOrderLog.getId() != null) criteria.andIdEqualTo(payOrderLog.getId());
        }
        example.setOrderByClause("BusinessCreateTime ASC");
        return payOrderLogMapper.selectByExampleWithBLOBs(example);
    }

}
